#include "test.h"

#undef ARRAY_SIZE
#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))

typedef int (*main_t) (int , char **);
typedef struct {
    char *name;
    main_t func;
} testfunc_t;

testfunc_t test_table[] = {
    {"signal", signal_test},
    {"errno", errno_test},
    {"setjmp", setjmp_test},
    {"float", float_test},
    {"stdio", stdio_test},
    {"fenv", fenv_test},
    {"complex", complex_test},
    {"stdlib", stdlib_test},
    {"malloc", malloc_test},
    {"time", time_test},
    {"locale", locale_test},
    {"getenv", getenv_test},
    {"sound", sound_test},
};

int main(int argc, char *argv[])
{
    int retval = -1;
    if (argc == 1) { /* print tests */
        printf("test case list:\n");
        int i;
        for (i = 0; i < ARRAY_SIZE(test_table); i++)
            printf("%s\n", test_table[i].name);
    
    } else if (argc >= 2) {
        printf("testing start...\n");
        char *p = argv[1];
        int i;
        for (i = 0; i < ARRAY_SIZE(test_table); i++)
            if (!strcmp(p, test_table[i].name)) {
                retval = test_table[i].func(argc, argv);
                printf("\ntest %s demo done.\n", test_table[i].name);
                break;
            }
        if (i >= ARRAY_SIZE(test_table))
            printf("test %s demo not found!\n", p);
    }    
    return retval;
}
